package dataInit

import (
	"bugManagementPlatform/pojo"
	"bugManagementPlatform/variable"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"time"
)

type MysqlInit struct {
}

var (
	err error
)

func init() {
	dsn := "root:new_password@tcp(127.0.0.1:3306)/bug_management_platform?charset=utf8mb4&parseTime=True&loc=Local"
	variable.Db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("db error")
	}
	variable.Fdb = variable.Db

	sqlDb, pErr := variable.Db.DB()
	if pErr != nil {
		panic("db error")
	}
	sqlDb.SetMaxIdleConns(10)
	sqlDb.SetMaxOpenConns(100)
	sqlDb.SetConnMaxLifetime(time.Hour)

	variable.Db.AutoMigrate(&pojo.Field{}, &pojo.Option{}, pojo.Project{}, &pojo.ProjectField{}, pojo.Case{}, pojo.CaseField{}, pojo.User{}, &pojo.TestReport{})
}
